<%-- 
    Document   : ProductView
    Created on : Mar 30, 2014, 6:16:48 PM
    Author     : asmaa
--%>

        <%@include file="headerAdmin.jsp" %>  
        <script>
            function validateProductEdit()
            {
                var name = document.forms["add"]["name"].value;
                var regexName = /^[a-zA-Z0-9\s]+$/;
                if (!regexName.test(name))
                {
                    alert("Name should not contain special character");
                    document.add.name.focus();
                    return false;
                }
                var description = document.forms["add"]["description"].value;
                var regexName = /^[a-zA-Z0-9\s\,\\]+$/;
                if (!regexName.test(name))
                {
                    alert("Name should not contain special character");
                    document.add.description.focus();
                    return false;
                }
                var fuData = document.getElementById('image');
                var FileUploadPath = fuData.value;
                if (FileUploadPath != '') {
                    var Extension = FileUploadPath.substring(FileUploadPath.lastIndexOf('.') + 1).toLowerCase();
                    //alert(Extension);
                    if (Extension != "gif" && Extension != "png" && Extension != "bmp" && Extension != "jpeg" && Extension != "jpg") {
                        alert("Photo only allows file types of GIF, PNG, JPG, JPEG and BMP. ");
                        document.add.image.focus();
                        return false;
                    }
                }
                var quantity = document.forms["add"]["quantity"].value;
                var regexQuantity = /^\d{1,6}$/;
                if (!regexQuantity.test(quantity))
                {
                    alert("Quantity should be decimal number");
                    document.add.quantity.focus();
                    return false;
                }
                var price = document.forms["add"]["price"].value;
                var regexPrice = /^\d*\.?\d*$/;
                if (!regexPrice.test(price))
                {
                    alert("Price can be float or integer number ");
                    document.add.price.focus();
                    return false;
                }
            }
        </script>
        

        <sql:query dataSource="${conn}" var="result">
            SELECT * from Product where id=?
            <sql:param value="${param.id}" />
        </sql:query>
        <script>
            function gobackProd(id)
            {
                location.href = "productlistadminview.jsp?id=" + id;
            }
        </script>
        <div class="top_bg">
            <div class="wrap">
                <div class="main_top">
                    <h2 class="style">View Product</h2>
                </div>
            </div>
        </div>
        <div class="container">
            <div class="row">
                <div class="col-md-6" style="margin-left: 60px;margin-top: 20px">
                    <c:forEach var="row" items="${result.rows}">
                        <form role="form"  >

                            <div class="form-group">

                                <img src="DisplayImage?id=${row.id}" style="height:250px;weidth:300px;" alt="Responsive image"><br>
                            </div>
                            <div class="form-group">
                                <label for="name">Name</label><br>
                                <input type="text" disabled value="${row.name}">
                            </div>
                            <div class="form-group">
                                <label for="description">Description</label><br>
                                <textarea  disabled >${row.description}</textarea>
                            </div>
                            <div class="form-group">
                                <label for="quantity">Quantity</label><br>
                                <input type="text" disabled value="${row.quantity}">
                            </div>
                            <div class="form-group">
                                <label for="price">Price</label><br>
                                <input type="text" disabled value="${row.price}">
                            </div>
                            <div class="form-group">
                                <button type="button" onclick="gobackProd(${row.categoryId})"class="btn btn-sm btn-success">Back</button>
                            </div>
                        </c:forEach>   
                    </form>
                </div>
            </div>
        </div>
        <%@include file="footer.jsp" %>
